package com.bj.zspace.redis.study;

import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import static com.bj.zspace.redis.study.ShuSeqiuUtils.*;

public class ShuaSeqiuHistory1 {

    public static void main(String[] args) throws Exception {
        Map<Integer, Integer> blueMap = new ConcurrentHashMap();
        Map<Integer, Integer> redMap = new ConcurrentHashMap<>();
        List<String> redSet = new ArrayList<>();
        List<String> redSet1 = new ArrayList<>();
        List<String> redSet2 = new ArrayList<>();

        List<String> redSet22 = new ArrayList<>();
        List<String> redSet4 = new ArrayList<>();
        List<String> redSet6 = new ArrayList<>();
        List<String> redSet8 = new ArrayList<>();
        Map<String, Integer> redMap01 = new ConcurrentHashMap<>();

        Map<String, Integer> redMap011 = new ConcurrentHashMap<>();

        Map<String, Integer> redMap02 = new ConcurrentHashMap<>();


        for (int i = 1; i <= 10; i++) {
            System.out.println("正在获取第" + i + "页数据...");
            String response = ShuSeqiuUtils.get("https://www.cwl.gov.cn/cwl_admin/front/cwlkj/search/kjxx/findDrawNotice?name=ssq&issueCount=&issueStart=&issueEnd=&dayStart=&dayEnd=&pageNo=" + i + "&pageSize=30&week=&systemType=PC");
            JSONObject entries = JSONUtil.parseObj(response);
            JSONArray result = entries.getJSONArray("result");
            for (Object obj : result) {
                JSONObject json = (JSONObject) obj;
                String redStr = json.getStr("red");
                String[] splitArray = redStr.split(",");
                Integer blue = json.getInt("blue");
                Integer blueCount = blueMap.get(blue);
                if (blueCount == null) {
                    blueMap.put(blue, 1);
                } else {
                    blueMap.put(blue, blueCount + 1);
                }
                /*for (String simpleRed : splitArray) {
                    Integer readCount = redMap.get(Integer.valueOf(simpleRed));
                    if (readCount == null) {
                        redMap.put(Integer.valueOf(simpleRed), 1);
                    } else {
                        redMap.put(Integer.valueOf(simpleRed), readCount + 1);
                    }
                }*/

                Integer startNum111 = redMap01.get(splitArray[3]);
                if (startNum111 == null) {
                    redMap01.put(splitArray[3], 1);
                } else {
                    redMap01.put(splitArray[3], startNum111 + 1);
                }

                /*if (splitArray[0].equals("02")) {
                    Integer startNum1 = redMap01.get(splitArray[1] + "");
                    if (startNum1 == null) {
                        redMap01.put(splitArray[1] + "", 1);
                    } else {
                        redMap01.put(splitArray[1] + "", startNum1 + 1);
                    }
                }*/

                /*Integer startNum1 = redMap01.get(splitArray[3]);
                if (startNum1 == null) {
                    redMap01.put(splitArray[3], 1);
                } else {
                    redMap01.put(splitArray[3], startNum1 + 1);
                }*/


                /*Integer startNum1 = redMap01.get(redStr.substring(0, 5));
                if (startNum1 == null) {
                    redMap01.put(redStr.substring(0, 5), 1);
                } else {
                    redMap01.put(redStr.substring(0, 5), startNum1 + 1);
                }*/


                if (splitArray[2].equals("22")) {
                    String treeRed = redStr.substring(12);
                    Integer startNum = redMap02.get(String.valueOf(splitArray[2] + splitArray[3] + splitArray[4] + splitArray[5]));
                    if (startNum == null) {
                        redMap02.put(String.valueOf(String.valueOf(splitArray[2] + splitArray[3] + splitArray[4] + splitArray[5])), 1);
                    } else {
                        redMap02.put(String.valueOf(String.valueOf(splitArray[2] + splitArray[3] + splitArray[4] + splitArray[5])), startNum + 1);
                    }
                    if (treeRed.startsWith("19")) {
                        redSet1.add(treeRed + "," + blue);
                    }
                }

                if (splitArray[2].equals("10") && splitArray[3].equals("14")) {
                    redSet2.add(redStr + "," + blue);
                }

               /* if (redStr.startsWith("02,05,13,17,29,33")) {
                    redSet22.add(redStr + "," + blue);
                }*/
                /*
                if (redStr.startsWith("01,06")) {
                    redSet4.add(redStr + "," + blue);
                }
                if (redStr.startsWith("02,07,09")) {
                    redSet6.add(redStr);
                }
                if (redStr.contains("06")) {
                    redSet8.add(redStr);
                }
                */


            }
        }

        sortPrintln1(blueMap, "所有蓝色球");
        sortPrintln1(redMap, "所有红色球");
        sortPrintln(redMap01, "红色第一个球");
        sortPrintln(redMap011, "红色第二个球");
        sortPrintln(redMap02, "newReadO2Map");
        println(redSet, "redSet");
        println(redSet1, "redSet1");
        println(redSet2, "redSet2");
        println(redSet22, "redSet22");
        println(redSet4, "redSet4");
        println(redSet6, "redSet6");
        println(redSet8, "redSet8");
    }


}
